package com.wc.codeforces.思维.Robert_Hood_and_Mrs_Hood;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/11 19:28
 * @description https://codeforces.com/problemset/problem/2014/D
 */
public class Main {
    /**
     * 思路：<p>
     * 查看当前位置的 i - d + 1, i 中的不同个数如何计算呢, 那是不是只需要判断这段区间有几个加入了, i - d 表示退出<p>
     * 这个思想就可以left[i] 存储当前从 i 要开始的任务书, right[i] 表示到 i 结束的任务数<p>
     * 当前的不同数如何计算呢 num += left[i] - right[i - d], 判断当前num与最大值，最小值就可以了
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int[] left = new int[N], right = new int[N];
    static int n, d, k;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            d = sc.nextInt();
            k = sc.nextInt();
            Arrays.fill(left, 1, n + 1, 0);
            Arrays.fill(right, 1, n + 1, 0);
            while (k-- > 0) {
                int l = sc.nextInt(), r = sc.nextInt();
                left[l]++;
                right[r]++;
            }
            int num = 0, resD = 0, resM = 0, maxv = 0, minv = N;
            for (int i = 1; i <= n; i++) {
                num += left[i] - right[Math.max(0, i - d)];
                if (num > maxv && i >= d) {
                    maxv = num;
                    resD = i - d + 1;
                }
                if (num < minv && i >= d) {
                    minv = num;
                    resM = i - d + 1;
                }
            }
            out.println(resD + " " + resM);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
